<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function Login(){
       if(IS_POST){
            $code = I('code');
            $verify = new \Think\Verify(); 
            $bool = $verify->check($code);
            if(!$bool){
                $this->error('验证码错误，请重新输入！');
                exit();
            }
            $user=D('user');
            $map['username|email'] = I('username');
            $map['password'] = I('password','','md5'); 
            $userlist = $user->where($map)->find();
            if($userlist){
                $_SESSION['Info'] = $userlist;
                $this->success('登陆成功',U('index/index'));
            }
            else{
                $this->error('用户名或者密码错误！');
                exit();
            }

           
           
       }
       else {
       $this->display();    
       }   
    }
        public function Code(){
        $config =    array(
        'fontSize'    =>    30,    // 验证码字体大小
        'length'      =>    4,     // 验证码位数
        'useNoise'    =>    false,
        'imageW'      =>  320,
        );
        $Verify =     new \Think\Verify($config);
        $Verify->entry();
    }
    public function loginout(){
        unset($_SESSION['Info']);
        $this->redirect('login/login');
    }
}